﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using StorySmith;
using System.Diagnostics;

namespace StorySmithTests.CalculatorStory
{   
    
        public class NumberOne
        {

            public int Value;
            public NumberOne()
            {
                Value = 1;
            }
        }

        public class NumberTwo : IGiven
        {
            public int Value;
            public void DoWork()
            {
                Value = 2;
            }
        }

        public class NumberThree 
        {
            public int Value;
            [SetUp]
            public void DoWhatever()
            {
                Value = 3;
            }
        }

        public class NumberFour  :IGiven
        {
             public int Value;
           
            public void DoWork()
            {
                Value = 4;
            }
        }

        
        public class CalculatorStory:IStory
        {

            #region IStory Members

            public string AsA
            {
                get
                 {
                    return "calculator user";
                }
                set{}
            }
            public string IWantTo
            {
                get
                {
                    return "add and subtract";

                }
                set{}
            }
            public string SoThat
            {
                get
                {
                    return "I can do complex calculations";
                }
                set { }
            }

            #endregion
        }

        public class Given_Two_Numbers
        {
            [TestFixture]
            public class When_they_are_subtracted
            {
                NumberOne number_one = new NumberOne();
                NumberTwo number_two = new NumberTwo();

                [SetUp]
                public void GivenTheseConditions()
                {
                    Behavior.For(new Story{AsA="calculator user", 
                                            IWantTo="add and subtract",SoThat="I can do complex calculations"})
                            .Given(number_one).And(number_two);
                }

                [Test]
                public void the_difference_should_be_one()
                {
                    int expected = 1;
                    int actual = number_two.Value - number_one.Value;
                    Behavior.Should(() => Assert.AreEqual(expected, actual, "two - one = one"));
                }
            }

            [TestFixture]
            public class When_they_are_added
            {
                NumberThree number_three = new NumberThree();
                NumberFour number_four = new NumberFour();

                [SetUp]
                public void GivenTheseConditions()
                {

                    Behavior.For(new CalculatorStory()).Given(number_three).And(number_four);


                }

                [Test]
                public void the_result_should_be_seven()
                {

                    int expected = 7;
                    int actual = number_four.Value + number_three.Value;
                    Behavior.Should(() => Assert.AreEqual(expected, actual, "three + four = seven"));


                }


            }

            [TestFixture]
            public class When_they_are_multiplied
            {
                [SetUp]
                public void GivenTheseConditions()
                {   
                    Behavior.For(new CalculatorStory()).Given(5," of value 5 ").And(10," of value 10 ");
                    
                }

                [Test]
                public void the_result_should_be_fifty()
                {

                    int expected = 50;
                    int actual = 5*10;
                    Behavior.Should(() => Assert.AreEqual(expected, actual, "5 * 10 = 50"));


                }
            }

        }

    }

